package com.bjpowernode.web;

import com.bjpowernode.entity.TActivityRemark;
import com.bjpowernode.query.ActivityRemarkQuery;
import com.bjpowernode.result.R;
import com.bjpowernode.service.ActivityRemarkService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 *
 */
@Slf4j
@RestController
@RequestMapping("/api/activityRemark")
public class ActivityRemarkController {

    @Resource
    private ActivityRemarkService activityRemarkService;

    @GetMapping("")
    public R userByPage(@RequestParam(value = "id") Integer id,
                        @RequestParam(value = "current", defaultValue = "1") Integer current) {
        log.info("id : {}  ,  current {}", id, current);
        PageInfo<TActivityRemark> activityPageInfo = activityRemarkService.getActivityByPage(id, current);
        log.info("值 : " + activityPageInfo.getPageSize());
        return R.OK(activityPageInfo);
    }

    @GetMapping("{id}")
    public R getActivityById(@PathVariable Integer id) {
        log.info("要获取的活动备注信息id : {}", id);
        TActivityRemark tActivityRemark = activityRemarkService.getActivityById(id);
        return R.OK(tActivityRemark);
    }

    @PutMapping("")
    public R updateActivityRemark(@RequestBody ActivityRemarkQuery activityRemarkQuery,
                                  @RequestHeader(value = "Authorization") String jwt) {
        log.info("要更新的备注信息数据activityRemarkQuery : {}" , activityRemarkQuery);
        activityRemarkQuery.setJwt(jwt);
        int update = activityRemarkService.updateActivityRemark(activityRemarkQuery);
        return update >= 1 ? R.OK() : R.FAIL();
    }


    @DeleteMapping("{id}")
    public R remove(@PathVariable(value = "id") Integer id) {
        log.info("要逻辑删除的备注信息id为 : {}" , id);
        //逻辑删除：不删数据，只是修改一下数据状态  --->  其实是一个更新操作
        //物理删除：直接把数据从数据库彻底删除
        int del = activityRemarkService.removeActivityRemarkById(id);
        return del >= 0 ? R.OK() : R.FAIL();
    }
}
